import { VulnerabilityManagementEntityType as EntityType } from 'utils/entityRelationships';

export const entityNounOrdinaryCaseSingular: Record<EntityType, string> = {
    CLUSTER: 'cluster',
    CLUSTER_CVE: 'platform CVE',
    DEPLOYMENT: 'deployment',
    IMAGE: 'image',
    IMAGE_COMPONENT: 'image component',
    IMAGE_CVE: 'image CVE',
    NAMESPACE: 'namespace',
    NODE: 'node',
    NODE_COMPONENT: 'node component',
    NODE_CVE: 'node CVE',
};

export const entityNounOrdinaryCasePlural: Record<EntityType, string> = {
    CLUSTER: 'clusters',
    CLUSTER_CVE: 'platform CVEs',
    DEPLOYMENT: 'deployments',
    IMAGE: 'images',
    IMAGE_COMPONENT: 'image components',
    IMAGE_CVE: 'image CVEs',
    NAMESPACE: 'namespaces',
    NODE: 'nodes',
    NODE_COMPONENT: 'node components',
    NODE_CVE: 'node CVEs',
};

export function entityNounOrdinaryCase(count: number, entityType: EntityType): string {
    return count === 1
        ? entityNounOrdinaryCaseSingular[entityType]
        : entityNounOrdinaryCasePlural[entityType];
}

export function entityCountNounOrdinaryCase(count: number, entityType: EntityType): string {
    return `${count} ${
        count === 1
            ? entityNounOrdinaryCaseSingular[entityType]
            : entityNounOrdinaryCasePlural[entityType]
    }`;
}
/*
 * If we computed sentence case via lodash,
 * it would require upperFirst instead of capitalize:
 * upperFirst('image CVE') returns 'Image CVE'
 * capitalize('image CVE') returns 'Image cve'
 */

export const entityNounSentenceCaseSingular: Record<EntityType, string> = {
    CLUSTER: 'Cluster',
    CLUSTER_CVE: 'Platform CVE',
    DEPLOYMENT: 'Deployment',
    IMAGE: 'Image',
    IMAGE_COMPONENT: 'Image component',
    IMAGE_CVE: 'Image CVE',
    NAMESPACE: 'Namespace',
    NODE: 'Node',
    NODE_COMPONENT: 'Node component',
    NODE_CVE: 'Node CVE',
};

// Instead of pluralize, which returns CVES instead of CVEs.
export const entityNounSentenceCasePlural: Record<EntityType, string> = {
    CLUSTER: 'Clusters',
    CLUSTER_CVE: 'Platform CVEs',
    DEPLOYMENT: 'Deployments',
    IMAGE: 'Images',
    IMAGE_COMPONENT: 'Image components',
    IMAGE_CVE: 'Image CVEs',
    NAMESPACE: 'Namespaces',
    NODE: 'Nodes',
    NODE_COMPONENT: 'Node components',
    NODE_CVE: 'Node CVEs',
};

export function entityNounSentenceCase(count: number, entityType: EntityType): string {
    return count === 1
        ? entityNounSentenceCaseSingular[entityType]
        : entityNounSentenceCasePlural[entityType];
}
